﻿$(function () {
    //参考地址：http://bv.doc.javake.cn/valIdators/
    //每个新增/编辑页面必备
    $('#frmEdit').bootstrapValidator({
        //是否启用验证
        live: "enabled",
        //提交按钮
        submitButtons: 'input[type="submit"]',
        //公共验证失败消息
        message: "值没有验证通过！",
        //验证成功或者失败的图标
        //feedbackIcons: {
        //    valid: 'glyphicon glyphicon-ok',
        //    invalid: 'glyphicon glyphicon-remove',
        //    validating: 'glyphicon glyphicon-refresh'
        //},
        fields: {
            UName: {
                message: '用户名验证失败',
                validators: {
                    notEmpty: {
                        message: '用户名不能为空'
                    }

                }
            },
            UPwd: {
                validators: {
                    notEmpty: {
                        message: '邮箱不能为空'
                    }

                }
            }
        },
        submitHandler: function (validator, form, submitButton) {
            //所有验证通过后，才会执行表单提交
            $("#frmEdit").ajaxSubmit({
                dataType: "json",
                data: $("#frmEdit").serialize(),
                success: function (data) {
                    if (data.Status > 0) {
                        bootbox.dialog({
                            message: "保存信息成功！",
                            title: "成功",
                            className: "",
                            buttons: {
                                success: {
                                    label: "确定",
                                    className: "btn-palegreen",
                                    callback: function () {
                                        location.href = options.listUrl;
                                    }
                                }
                            }
                        });
                    }
                    else {
                        bootbox.dialog({
                            message: data.Message,
                            title: "失败",
                            className: "modal-danger",
                            buttons: {
                                success: {
                                    label: "确定",
                                    className: "btn-danger"
                                }
                            }
                        });
                    }
                }
            });
            return false;
        }
    });

    //返回按钮事件
    $("#btnReturn").click(function (e) {
        window.location.href = options.listUrl;
    });

});



